#!/bin/bash

CMD_SED="/bin/sed"
CMD_DATE="/bin/date"
CMD_ECHO="/bin/echo"
CMD_AWK="/usr/bin/awk"
CMD_LOG="/usr/bin/logger"
CMD_BC="/usr/bin/bc"
CMD_WC="/usr/bin/wc"
CMD_CURL="/usr/bin/curl"
PID_FILE="/tmp/check_req_sec.pid"

if [ -f ${PID_FILE} ]; then
	echo "ja em execucao"
	exit 2
else
	touch ${PID_FILE}
fi


TIMESTAMP=$(${CMD_DATE} +%s)

# Printing Client requests received
req_sec="`${CMD_CURL} -s http://loghost:8080/server-statistics | grep qttyRequest5min | grep td | grep -v style | cut -d '>' -f 2 | cut -d '<' -f 1
uolmais_req_sec="`echo "$req_sec/300" | bc`"


${CMD_ECHO} "UOLGRAPH check_req_sec 10 ${HOSTNAME} AGENTE_LASTRUN ${TIMESTAMP} uolmais_req_sec ${uolmais_req_sec}" | ${CMD_LOG} -p local5.info -t UOL007

rm -f ${PID_FILE}
